home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60 / 60.xpi / chrome / webdeveloper.jar / content / webdeveloper / generated / table_pivot.js < prev    next >
Encoding:
JavaScript  |  2009-06-30  |  2.4 KB  |  80 lines

  1. // Makes all tables on the page with a cell with a pivot class pivotable
  2. function webdeveloper_makeTablesPivotable()
  3. {
  4.     var tableCellList   = webdeveloper_evaluateXPath(document, "//td[@class='pivot']");
  5.     var tableCellLength = tableCellList.length;
  6.  
  7.     // Loop through the table cells
  8.     for(var i = 0; i < tableCellLength; i++)
  9.     {
  10.         tableCellList[i].addEventListener("click", webdeveloper_pivotTable, false);
  11.     }
  12. }
  13.  
  14. // Pivots a table
  15. function webdeveloper_pivotTable(event)
  16. {
  17.     // If the event is set
  18.     if(event)
  19.     {
  20.         var hide      = true;
  21.         var pivotRow  = event.target.parentNode;
  22.         var tableCell = null;
  23.         var tableRow  = pivotRow;
  24.  
  25.         // If the pivot row class attribute is set to collapsed
  26.         if(pivotRow.getAttribute("class") == "collapsed")
  27.         {
  28.             hide = false;
  29.  
  30.             pivotRow.setAttribute("class", "expanded");
  31.         }
  32.         else
  33.         {
  34.             pivotRow.setAttribute("class", "collapsed");
  35.         }
  36.  
  37.         // Loop through the table rows
  38.         while((tableRow = tableRow.nextSibling) != null)
  39.         {
  40.             tableCell = tableRow.firstChild;
  41.  
  42.             // If the table cell is set and has a class attribute set to indent
  43.             if(tableCell && tableCell.hasAttribute("class") && tableCell.getAttribute("class") == "indent")
  44.             {
  45.                 // If the table row has a class attribute that contains shaded
  46.                 if(tableRow.hasAttribute("class") && tableRow.getAttribute("class").indexOf("shaded") != -1)
  47.                 {
  48.                     // If hiding the row
  49.                     if(hide)
  50.                     {
  51.                         tableRow.setAttribute("class", "hidden shaded");
  52.                     }
  53.                     else
  54.                     {
  55.                         tableRow.setAttribute("class", "shaded");
  56.                     }
  57.                 }
  58.                 else
  59.                 {
  60.                     // If hiding the row
  61.                     if(hide)
  62.                     {
  63.                         tableRow.setAttribute("class", "hidden");
  64.                     }
  65.                     else
  66.                     {
  67.                         tableRow.removeAttribute("class");
  68.                     }
  69.                 }
  70.             }
  71.             else
  72.             {
  73.                 break;
  74.             }
  75.         }
  76.     }
  77. }
  78.  
  79. webdeveloper_makeTablesPivotable();
  80.